import {View} from "@tarojs/components";
import "./orderInformation.less"
import store from "../../../store";
import Text from "antd/es/typography/Text";
import {useEffect, useState} from "react";
import {toJS} from "mobx";
import Taro from "@tarojs/taro";
import { AtToast } from "taro-ui"
import http from "../../../service/api";

const OrderInformation=()=>{
    useEffect(()=>{
        // console.log(toJS(store.orderInformation))
    },[])
    const [data,setData]=useState(toJS(store.orderInformation))
    const btn = ()=>{
    let text = ""
    if (data.type=="待发货"){
        text="催发货"
    }else if (data.type=="待付款"){
        text="去付款"
    }else if (data.type=="已发货"){
        text="查看物流"
    }else if (data.type=="已完成"){
        text="查看物流"
    }
    return text
}
    const click=()=>{
        store.setDataId(data.id)
         Taro.navigateTo({
           url: "../../details/details"
       })
    }
    const [t,setT]=useState(false)
    const [t2,setT2]=useState(false)
    const btnClick=(e)=> {
        if (data.type == "待发货") {
            //    催发货
            setT(true)
        } else if (data.type == "待付款") {
            console.log(data)
            //调用支付接口，发送订单编号data。oid,data.price,data.name
            Taro.request({
                url: http.api2 + "/aliPay/pay",
                method: "get",
             /*   header: {
                    'content-type': 'application/x-www-form-urlencoded' // 默认值
                },*/
                data: {
                    dcosts:data.pay,
                    gName:data.name,
                    orderId:data.oid
                },
                success(res) {
                    console.log(res)},
                fail(err) {
                    console.log("失败了")
                }
            })
            //    成功后跳转到全部订单页面
        } else if (data.type == "已发货"||data.type == "已完成") {
            setT2(true)
        }
    }
    return(
        <View className="orderInformation">
        <View className="title">{data.type}</View>
            <View className="list">
                <View className='at-icon at-icon-bullet-list'/>
                <View className="data">
                    <View className="num">订单编号 {data.oid}</View>
                    <View className="time">下单时间 {data.orderTime}</View>
                </View>
            </View>
            <View className="list">
                <View className='at-icon at-icon-user'/>
                <View className="data">
                    <View className="num">
                        {store.userData.nickName} {store.userPhone}
                    </View>
                    <View className="time">{data.address}</View>
                </View>
            </View>
            <View className="list" onClick={click}>
                <View className='at-icon at-icon-shopping-bag'/>
                <View className="data">
                    <View className="num">{data.name}</View>
                    <View className="time">
                        {data.specification} X{data.num}
                    </View>
                    <View className='at-icon at-icon-chevron-right'/>
                </View>
            </View>
            <View className="list">
                <View className='at-icon at-icon-tags'/>
                <View className="data">
                    <View className="num">实付{data.pay}</View>
                    <View className="time">快递费0.00元</View>
                </View>
            </View>
            <View className="btn" onClick={btnClick}>
                {btn()}
            </View>
            <AtToast isOpened={t} text="已提醒商家发货" icon="check - circle" onClose={()=>{setT(false)}}/>
            <AtToast isOpened={t2} text="暂无物流信息" onClose={()=>{setT2(false)}}/>
        </View>
    )
}
export default OrderInformation